package com.tc.alarm;

import com.alibaba.nacos.common.utils.StringUtils;
import com.tc.alarm.impl.MailAlarmHelper;
import com.tc.alarm.impl.SmsAlarmHelper;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
@Configuration
@RefreshScope
public class AlarmConfig {
    @Value("${alarm.type}")
    private String alarmType;
    @Bean
    @RefreshScope
    public AlarmInterface alarmHelper(){
        // 根据配置文件的告警类型初始化不同的告警实现类
        if (StringUtils.equals("sms", alarmType)){
            return new SmsAlarmHelper();
        }else if (StringUtils.equals("email", alarmType)){
            return new MailAlarmHelper();
        }else {
            throw new IllegalArgumentException("错误的告警类型..");
        }
    }
}
